#include "InputManager.h"

InputManager* InputManager::s_Instance = 0;

InputManager* InputManager::GetInstance()
{
	if (!s_Instance)
	{
		s_Instance = new InputManager();
	}
	return s_Instance;
}

InputManager::InputManager()
{
	for (int i = 0; i <= 255; i++)
		m_KeyDown[i] = false;
	m_PointerX = 0;
	m_PointerY = 0;
}


InputManager::~InputManager()
{
	
}

void InputManager::OnKey(int keyCode, bool isKeyDown)
{
	m_KeyDown[keyCode] = isKeyDown;
}

void InputManager::OnMouse(int type, int x, int y)
{
	m_PointerX = x;
	m_PointerY = y;
	m_PointerState = type;
}

bool InputManager::IsKeyDown(int KeyCode)
{
	return m_KeyDown[KeyCode];
}

bool InputManager::IsPointerDown()
{
	return (m_PointerState == 0);
}

bool InputManager::IsPointerDrag()
{
	return (m_PointerState == 2);
}

bool InputManager::IsPointerInRect(bool &down, int x, int y, int w, int h)
{
	down = IsPointerDown();
	return m_PointerX >= x && m_PointerX <= x + w && m_PointerY >= y && m_PointerY <= y + h;
}